# this is made by Nout, and it sucks :)
# reads from 'inp' input file + .txt as crypt string
# reads from 'inp' + -key.txt' as replace file
# shows some stupid counts
# asks for substring, and shows suboccurences
crypt = ''
inp = 'monop1'
fc = open(inp + '.txt', 'r')

for line in fc.readlines(): 
	crypt += line
fc.close
crypt = crypt.replace(' ', '')
crypt = crypt.replace('\n', '')
print 'crypt string: \n\t' + crypt

sol = crypt

# a - z
for i in range(97,122):
	print chr(i), '\t', crypt.count(chr(i))

fk = open(inp + '-key.txt', 'r')
for line in fk.readlines():
	sol = sol.replace(line[0], line[2])
fk.close
print 'solution?: \n\t' + sol




while (1):
	x = raw_input('which substr to check?\t')
	#print 'substr:' + x
	be = {}
	af = {}
	j = 0
	p = 0
	lenx = len(x)
	while (p > -1):
		p = crypt.find(x, j)
		if (p > 0):
			prevc = crypt[p - 1] 
			#print "pos %s chr %s curchr %s" % (p - 1, prevc, crypt[p])
			if (prevc in be):
				be[prevc] += 1
			else:
				be[prevc] = 1
		if (p > -1 and p < len(crypt) - 1):
			nextc = crypt[p + lenx]
 			#print "Pos %s chr %s curchr %s" % (p + lenx, nextc, crypt[p])
			if (nextc in af):
				af[nextc] += 1
			else:
				af[nextc] = 1

		#print p
		j = p + 1

	#print 'before: ' 
	#print be
	str1 = ''
	str2 = ''
	for k in be:
		str1 += "%s%s\t" % (k,x)
		str2 += "%s\t" % be[k]
#		if (be[k] < 10):
#			str2 += " "
		#"%s%s: %s" % (k,x,be[k])
	print str1
	print str2
	str1 = "\t"
	str2 = "\t"
	for k	 in af:
		str1 += "%s%s\t" % (x,k)
		str2 += "%s\t" % af[k]

#		if (af[k] < 10):
#			str2 += " "

	print str1
	print str2



		

